<?php
namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Admin extends Model
{
	protected $table = 'admindata';
	protected $primaryKey = 'id';
	public $timestamps = false;
	
	
	/**
	 * 获取管理员信息
	 * 
	 * @author wudi
	 */
	public static function get_admin_info($id){
	
		$admin = DB::table('admindata')->select('*')->where("id",$id)->first();
		$admin = (array)$admin;
		$admin['rights'] = isset($admin['rights']) ? explode('|', $admin['rights']) : [];
		return $admin;
	}

	public static function all_list($p=[]){
		$all = DB::table('admindata')->select('id','username');
		if(!empty($p['group_id'])){
			$all->where('group_id',$p['group_id']);
		}
		$all = $all->get()->toArray();
		return arrays_set_key($all,'id');
	}
}